// pages/me/setting/setting.js
import Util from '../../utils/utils';
import {
  HomeHttp
} from '../../api/home.js'
const homeModel = new HomeHttp();
Page({
  /**
   * 页面的初始数据
   */
  initStatus:false,
  data: {
    total:{
      thirdpartOrderCount:0,
      yddOrderCount:0,
      bonusOrderCount:0,
      flashTradeOrderCount:0,
    },
    zeroMoneyOrderNum: 0,
    version:Util.version,
    userInfo:{
      uid:0
    }
  },
  initPage: function() {
    let self = this;
    wx.hideShareMenu();
    self.initData();
    setTimeout(function () {
      self.initStatus = true;
    },100);
  },
  onPullDownRefresh: function() {
    this.initData();
  },
  onShow: function () {
    if(this.initStatus === true){
      this.initData();
    }
  },
  initData:function(){
    let self = this;
    wx.showNavigationBarLoading();
    this.getUserInfo(function(userInfo) {
      self.setData({
        userInfo:userInfo
      });
      Util.request({
        url:'/order/countStatistic',
        isJava:true,
        loading:2,
        callback:function (result) {
          let res = result.res;
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
          self.setData({
            total:res
          });
        },
        error:function () {
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
        }
      });
      self.httpGetOrderList()
    }, function() {
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    });
  },
  // 获取0元购订单数量
  httpGetOrderList() {
    homeModel.getSeckillOrderList({
      page: 1,
      page_size: 1
    }).then((res) => {
      this.setData({
        zeroMoneyOrderNum: res.total
      })
    })
  },
  toPage: function(event) {
    let login = true;
    if (event.currentTarget.dataset.login) {
      login = event.currentTarget.dataset.login;
    }
    if (!this.data.userInfo['uid'] && login === 'true') {
      Util.msg('需要登录后才能查看哦!');
      return false;
    }
    Util.toPage(event);
  },
});
